﻿package mortal.game.proxy
{
    import Engine.RMI.*;
    import Framework.Util.*;
    import Message.Game.*;
    import Message.Public.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.ai.ais.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class SceneProxy extends Proxy
    {
        private var _mapMove:AMI_IMap_move;
        private var _mapDiversion:AMI_IMap_diversion;
        private var _lastCovey:SPassTo;
        protected var lastPoint:SPoint;
        private var diversionTimeArray:Array;
        private var _lastNow:int;
        private var _lastTime:int = -1;
        private var pickupPlayerItem:SPlayerItem;

        public function SceneProxy()
        {
            this._mapMove = new AMI_IMap_move();
            this._mapDiversion = new AMI_IMap_diversion();
            this.lastPoint = new SPoint();
            this.diversionTimeArray = [];
            return;
        }// end function

        public function covey(param1:SPassTo) : void
        {
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                return;
            }
            this._lastCovey = param1;
            rmi.iMapPrx.convey_async(new AMI_IMap_convey(), param1.mapId, param1.toPoint);
            return;
        }// end function

        public function saveCustomMapPoint(param1:int, param2:String, param3:int, param4:SPoint) : void
        {
            rmi.iMapPrx.saveCustomPoint_async(new AMI_IMap_saveCustomPoint(), param1, param2, param3, param4);
            return;
        }// end function

        public function getCustomMapPoint() : void
        {
            rmi.iMapPrx.getCustomPoint_async(new AMI_IMap_getCustomPoint(this.onGetCustomMapPoint));
            return;
        }// end function

        private function onGetCustomMapPoint(param1:Object, param2:Array) : void
        {
            cache.smallmap.initCustomMapPoints(param2);
            NetDispatcher.dispatchCmd(ServerCommand.SmallMapCustomMapPointGot, null);
            return;
        }// end function

        public function clearLastPoint() : void
        {
            this.lastPoint = null;
            return;
        }// end function

        public function moveSelfPet(param1:Array) : void
        {
            rmi.iMapPrx.move_async(this._mapMove, param1);
            return;
        }// end function

        public function move(param1:Array) : void
        {
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                return;
            }
            if (GameMapUtil.curMapState.isWineMap && GameController.copy.winePartyCopy.isStartMora)
            {
                return;
            }
            if (param1.length > 0)
            {
                this.lastPoint = param1[(param1.length - 1)];
                rmi.iMapPrx.move_async(this._mapMove, param1);
            }
            return;
        }// end function

        public function diversion(param1:Array) : void
        {
            var _loc_2:int = 0;
            var _loc_3:SPoint = null;
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                return;
            }
            if (GameMapUtil.curMapState.isWineMap && GameController.copy.winePartyCopy.isStartMora)
            {
                return;
            }
            _loc_2 = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2] as SPoint;
                if (!this.lastPoint || _loc_3.x != this.lastPoint.x || _loc_3.y != this.lastPoint.y)
                {
                    break;
                }
                if (_loc_2 == (param1.length - 1))
                {
                    return;
                }
                _loc_2++;
            }
            this.lastPoint = param1[(param1.length - 1)];
            rmi.iMapPrx.diversion_async(this._mapDiversion, param1);
            return;
        }// end function

        public function relive(param1:int) : void
        {
            rmi.iMapPrx.revival_async(new AMI_IMap_revival(), param1);
            if (cache.role.entityInfo.life > 0)
            {
                GameController.relive.onRoleRelived();
            }
            return;
        }// end function

        public function jump(param1:SPoint) : void
        {
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                return;
            }
            RolePlayer.instance.spasticityFire();
            rmi.iMapPrx.jump_async(new AMI_IMap_jump(), param1);
            return;
        }// end function

        public function jumpPoint(param1:SPoint) : void
        {
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                return;
            }
            RolePlayer.instance.spasticityFire();
            rmi.iMapPrx.jumpPoint_async(new AMI_IMap_jumpPoint(), param1);
            return;
        }// end function

        public function somersault(param1:SPoint) : void
        {
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                return;
            }
            var _loc_2:* = new SPoint();
            _loc_2.x = RolePlayer.instance.x2d;
            _loc_2.y = RolePlayer.instance.y2d;
            var _loc_3:Array = [_loc_2, param1];
            RolePlayer.instance.spasticityFire();
            rmi.iMapPrx.somersault_async(new AMI_IMap_somersault(), _loc_3);
            return;
        }// end function

        public function pass(param1:EPassType, param2:int, param3:int, param4:SPoint) : void
        {
            if (this.CheckPass())
            {
                rmi.iMapPrx.pass_async(new AMI_IMap_pass(), param1, param2, param3, param4);
            }
            return;
        }// end function

        private function CheckPass() : Boolean
        {
            if (GameMapUtil.curMapState.isPetBreakMap)
            {
                return false;
            }
            if (GameMapUtil.curMapState.isTowerMap)
            {
                return GameController.copy.towerCopy.allowPassTo;
            }
            return true;
        }// end function

        public function sprint() : void
        {
            rmi.iMapPrx.sprint_async(new AMI_IMap_sprint());
            return;
        }// end function

        public function fight(param1:Array, param2:int = 0, param3:SPoint = null, param4:int = 0, param5:String = "", param6:Boolean = false) : void
        {
            var now:int;
            var entityIds:* = param1;
            var skillID:* = param2;
            var spoint:* = param3;
            var op:* = param4;
            var uid:* = param5;
            var defenseCopySkill:* = param6;
            if (GameMapUtil.unuseSkillMap)
            {
                return;
            }
            var info:* = cache.skill.getSkill(skillID);
            var fightTo:* = new SFightOper();
            fightTo.toEntitys = entityIds;
            fightTo.skillId = skillID;
            fightTo.op = op;
            if (ClientSetting.local.getIsDone(IsDoneType.IsNotCD))
            {
                fightTo.jsStr = "{\"fightOperNoCd\":1}";
            }
            else
            {
                fightTo.jsStr = "{\"fightOperNoCd\":0}";
            }
            if (info)
            {
                if (info.tSkill.name == "防御状态")
                {
                }
                now = getTimer();
                this._lastNow = now;
            }
            if (spoint == null)
            {
                fightTo.mousePoint = new SPoint();
            }
            else
            {
                fightTo.mousePoint = spoint;
            }
            if (defenseCopySkill)
            {
                var onFightSucceed:* = function (param1:AMI_IFight_fight) : void
            {
                NetDispatcher.dispatchCmd(ServerCommand.SkillSeriesItemAdd, skillID);
                NetDispatcher.dispatchCmd(ServerCommand.DefenseCopyRoleEquipUpdate, null);
                return;
            }// end function
            ;
                rmi.iFightPrx.fight_async(new AMI_IFight_fight(onFightSucceed), fightTo);
            }
            else
            {
                rmi.iFightPrx.fight_async(new AMI_IFight_fight(), fightTo);
            }
            if (!SkillUtil.isNoSpasticitySkill(info))
            {
                RolePlayer.instance.spasticityFire();
            }
            return;
        }// end function

        public function collect(param1:SEntityId, param2:Boolean = true) : void
        {
            var _loc_3:* = getTimer();
            if (_loc_3 - this._lastTime < 300)
            {
                return;
            }
            this._lastTime = _loc_3;
            rmi.iFightPrx.collect_async(new AMI_IFight_collect(), param1, param2);
            return;
        }// end function

        public function stopCollect() : void
        {
            rmi.iFightPrx.stopCollect_async(new AMI_IFight_stopCollect());
            return;
        }// end function

        public function pickup(param1:SEntityId, param2:SPlayerItem = null) : void
        {
            this.pickupPlayerItem = param2;
            rmi.iMapPrx.pickup_async(new AMI_IMap_pickup(this.pickupResponse, this.pickupEx), param1);
            return;
        }// end function

        private function pickupResponse(param1:AMI_IMap_pickup) : void
        {
            if (this.pickupPlayerItem && GameMapUtil.curMapState.isHoleBoss)
            {
                NetDispatcher.dispatchCmd(ServerCommand.WorldBossHolePickItem, this.pickupPlayerItem);
            }
            return;
        }// end function

        private function pickupEx(param1:Exception) : void
        {
            if (Cache.instance.pack.backPackCache.isFull && GameMapUtil.curMapState.isTowerMap && AutoFightAI.isWorking)
            {
                AIManager.cancelAll();
            }
            RMIDispatcher.getInstance().dispatchErrorEvent(param1);
            return;
        }// end function

        public function dispelBuffSelf() : void
        {
            rmi.iFightPrx.dispelBuffSelf_async(new AMI_IFight_dispelBuffSelf());
            return;
        }// end function

        public function changeFightMode(param1:int) : void
        {
            rmi.iFightPrx.setFightMode_async(new AMI_IFight_setFightMode(), param1);
            return;
        }// end function

        public function getZZXYBattleCardReward(param1:String) : void
        {
            rmi.iMapPrx.getRouletteDrop_async(new AMI_IMap_getRouletteDrop(), param1);
            return;
        }// end function

    }
}
